/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package jmmos.gameserver.ai;

import jmmos.gameserver.ThreadPoolManager;
import jmmos.gameserver.model.MMOCharPosition;
import jmmos.gameserver.model.MMOObject;
import jmmos.gameserver.model.actor.MMOCharacter;
import jmmos.gameserver.model.actor.instance.MMODefenderInstance;
import jmmos.gameserver.model.actor.instance.MMODoorInstance;
import jmmos.gameserver.model.skills.MMOSkill;

/**
 * @author mkizub
 */
public class MMODoorAI extends MMOCharacterAI
{
	public MMODoorAI(MMODoorInstance.AIAccessor accessor)
	{
		super(accessor);
	}
	
	// rather stupid AI... well, it's for doors :D
	@Override
	protected void onIntentionIdle()
	{
	}
	
	@Override
	protected void onIntentionActive()
	{
	}
	
	@Override
	protected void onIntentionRest()
	{
	}
	
	@Override
	protected void onIntentionAttack(MMOCharacter target)
	{
	}
	
	@Override
	protected void onIntentionCast(MMOSkill skill, MMOObject target)
	{
	}
	
	@Override
	protected void onIntentionMoveTo(MMOCharPosition destination)
	{
	}
	
	@Override
	protected void onIntentionFollow(MMOCharacter target)
	{
	}
	
	@Override
	protected void onIntentionPickUp(MMOObject item)
	{
	}
	
	@Override
	protected void onIntentionInteract(MMOObject object)
	{
	}
	
	@Override
	protected void onEvtThink()
	{
	}
	
	@Override
	protected void onEvtAttacked(MMOCharacter attacker)
	{
		MMODoorInstance me = (MMODoorInstance) _actor;
		ThreadPoolManager.getInstance().executeTask(new onEventAttackedDoorTask(me, attacker));
	}
	
	@Override
	protected void onEvtAggression(MMOCharacter target, int aggro)
	{
	}
	
	@Override
	protected void onEvtStunned(MMOCharacter attacker)
	{
	}
	
	@Override
	protected void onEvtSleeping(MMOCharacter attacker)
	{
	}
	
	@Override
	protected void onEvtRooted(MMOCharacter attacker)
	{
	}
	
	@Override
	protected void onEvtReadyToAct()
	{
	}
	
	@Override
	protected void onEvtUserCmd(Object arg0, Object arg1)
	{
	}
	
	@Override
	protected void onEvtArrived()
	{
	}
	
	@Override
	protected void onEvtArrivedRevalidate()
	{
	}
	
	@Override
	protected void onEvtArrivedBlocked(MMOCharPosition blocked_at_pos)
	{
	}
	
	@Override
	protected void onEvtForgetObject(MMOObject object)
	{
	}
	
	@Override
	protected void onEvtCancel()
	{
	}
	
	@Override
	protected void onEvtDead()
	{
	}
	
	private class onEventAttackedDoorTask implements Runnable
	{
		private final MMODoorInstance _door;
		private final MMOCharacter _attacker;
		
		public onEventAttackedDoorTask(MMODoorInstance door, MMOCharacter attacker)
		{
			_door = door;
			_attacker = attacker;
		}
		
		@Override
		public void run()
		{
			for (MMODefenderInstance guard : _door.getKnownDefenders())
			{
				if (_actor.isInsideRadius(guard, guard.getFactionRange(), false, true) && (Math.abs(_attacker.getZ() - guard.getZ()) < 200))
				{
					guard.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attacker, 15);
				}
			}
		}
	}
	
}
